package cn.edu.neusoft.yyd208.foodorder.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.yyd208.foodorder.activity.FoodInfoActivity;
import cn.edu.neusoft.yyd208.foodorder.activity.FoodListActivity;
import cn.edu.neusoft.yyd208.foodorder.bean.CollectListBean;

public class AllCollectAdapter extends BaseAdapter<CollectListBean>{
    String id,shopname,shopaddress,foodname,foodprice,foodintro;

    public AllCollectAdapter(Context context, List<CollectListBean> items, int layoutResource) {
        super(context, items, layoutResource);
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder,final int position) {
        ShopViewHolder myViewHolder=(ShopViewHolder)holder;
        final String id=items.get(position).getShop_id();
        //final String userid=items.get(position).getUser_id();
        final String foodid=items.get(position).getFood_id();
        final String foodintro=items.get(position).getFoodintro();
        final String foodimg=items.get(position).getPic();
        if(items.get(position).getFlag().equals("0")){
            shopname=items.get(position).getShopname();
            shopaddress=items.get(position).getAddress();

            myViewHolder.tv_shop.setText(shopname);
            myViewHolder.tv_address.setText(shopaddress);
            myViewHolder.tv_intro.setText(foodintro);
            Picasso.with(context).load("http://172.24.10.175:8080/foodService"+items.get(position).getPic()).into(myViewHolder.img_shop);
            myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.i("TEST", "onClick: ");
                    Intent intent=new Intent(context, FoodListActivity.class);
                    intent.putExtra("id",id);
                    intent.putExtra("shopname",shopname);
                    //intent.putExtra("userid",userid);
                    context.startActivity(intent);
                }
            });
        }
        else {
            final String foodname=items.get(position).getFoodname();
            final String foodprice=items.get(position).getPrice();
            myViewHolder.tv_shop.setText(foodname);
            myViewHolder.tv_address.setText(foodprice);
            myViewHolder.tv_intro.setText(foodintro);
            Picasso.with(context).load("http://172.24.10.175:8080/foodService"+items.get(position).getPic()).into(myViewHolder.img_shop);
            myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(context, FoodInfoActivity.class);
                    intent.putExtra("id",id);
                    intent.putExtra("foodname",foodname);
                    intent.putExtra("foodprice",foodprice);
                    intent.putExtra("foodintro",foodintro);
                    intent.putExtra("foodimg",foodimg);
                    intent.putExtra("foodid",foodid);
                    context.startActivity(intent);
                }
            });
        }
    }
}
